package com.xzl.manger.server;

import com.xzl.manger.dao.IAdminDao;
import com.xzl.manger.dao.IGoodsDao;
import com.xzl.manger.model.Admin;
import com.xzl.manger.model.Goods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class MyServer {
    @Autowired
    private IAdminDao adminDao;
    @Resource
    private IGoodsDao goodsDao;
    public List<Admin> selectAdmin(Admin ad){
        List<Admin> list = adminDao.selectAdmin(ad);
        return list;
    }

    public List<Admin> selectRoot(Admin root){
        List<Admin> list = adminDao.selectRoot(root);
        return list;
    }
    public Integer updateAdmin(Admin ad){
        if((ad.getName()!=null&&!ad.getName().isEmpty())||(ad.getPassword()!=null&&!ad.getPassword().isEmpty()))
        return adminDao.update(ad);
        else return 0;
    }
    public Integer deleteAdmin(Integer id){
        if(id!=null&&id!=0)
            return adminDao.delete(id);
        else
            return 0;
    }
    public Integer insertAdmin(Admin ad){
        if(ad.getName()!=null&&!ad.getName().isEmpty())
            return adminDao.insert(ad);
        else
            return 0;
    }
    public List<Admin> loginCheck(Admin ad){
        if(ad==null) return null;
        if(ad.getName()==null||ad.getPassword()==null||ad.getName().isEmpty()||ad.getPassword().isEmpty())
            return null;
        List<Admin> root = adminDao.selectRoot(ad);
        List<Admin> admin = adminDao.selectAdmin(ad);
        if (root!=null&&root.size()>0) return root;
        if (admin!=null&&admin.size()>0) return admin;

        return null;
    }
}
